import Vue from 'vue'
import VueRouter from 'vue-router'

//解决vue路由跳转报错Avoided redundant navigation to current location: “/xxxxxx“.路由重复跳转报错
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

import FindingMusic from '../pages/FindingMusic'
import Lately from '../pages/Lately'
import Recommend from '../pages/Recommend'
import SongList from '../pages/SongList'
import RankingList from '../pages/RankingList'
import UserProfile from '../pages/UserProfile'
import DailyList from '../pages/DailyList'
import Listing from '../pages/Listing'
import SearchResult from '../pages/SearchResult'
import Contacts from '../pages/Contacts'

const router = new VueRouter({
	routes:[
		{
			path: '/',
			redirect:'/FindingMusic/Recommend'
		},
		{
			path: "/FindingMusic",
			name: "FindingMusic",
			component: FindingMusic,
			children: [
				{
					path: "Recommend",
					name: "Recommend",
					component: Recommend,
				},
				{
					path: "SongList",
					name: "SongList",
					component: SongList,
				},
				{
					path: "RankingList",
					name: "RankingList",
					component: RankingList,
				},
			],
			//默认二级路由
			redirect:'/FindingMusic/Recommend'
		},
		{
			path: "/Lately",
			name: "Lately",
			component: Lately
		},
		{
			path: "/UserProfile",
			name: "UserProfile",
			component: UserProfile
		},
		{
			path: "/DailyList",
			name: "DailyList",
			component: DailyList
		},
		{
			path: "/Listing",
			name: "Listing",
			component: Listing,
		},
		{
			path: "/SearchResult",
			name: "SearchResult",
			component: SearchResult
		},
		{
			path: "/Contacts",
			name: "Contacts",
			component: Contacts
		}
	],
	redirect:'/FindingMusic/Recommend'
})

export default router